package com.yonyou.pmclouds.workflow.processor;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.workflow.entity.ProcessDefinitionVO;
import com.yonyou.pmclouds.workflow.mapper.ProcessDefinitionMapper;
import org.apache.commons.lang3.ArrayUtils;

public class DefinitionCheckRule implements SingleProcessor<ProcessDefinitionVO> {

    private ProcessDefinitionMapper definitionMapper;

    public DefinitionCheckRule(ProcessDefinitionMapper definitionMapper) {
        this.definitionMapper = definitionMapper;
    }

    @Override
    public void process(ProcessDefinitionVO vo, ProcessDefinitionVO orig) throws BusinessException {
        ProcessDefinitionVO[] processDefinitionVOs = definitionMapper.queryByNameAndOrg(vo.getProcessName(),vo.getPkTenant(),vo.getPkOrg());
        if(ArrayUtils.isNotEmpty(processDefinitionVOs))
            throw new BusinessException("该组织下存在相同名称的流程定义");
    }
}
